package com.aidex.system.service.impl;

import com.aidex.common.core.domain.model.LoginUser;
import com.aidex.common.core.service.impl.BasicServiceImpl;
import com.aidex.common.utils.SecurityUtils;
import com.aidex.system.domain.SysNoticeUserRead;
import com.aidex.system.mapper.SysNoticeUserReadMapper;
import com.aidex.system.service.SysNoticeUserReadService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(readOnly = true)
public class SysNoticeUserReadServiceImpl extends BasicServiceImpl<SysNoticeUserReadMapper, SysNoticeUserRead> implements SysNoticeUserReadService {

    @Override
    @Transactional
    public boolean setIsRead(String noticeId) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        SysNoticeUserRead read = new SysNoticeUserRead();
        read.setNoticeId(noticeId);
        read.setUserId(loginUser.getUser().getId());
        read.setIsRead("1");
        read.setStatus("0");
        try {
            //通过外键控制数据不能重复
            return this.updateById(read) > 0;
        } catch (Exception e) {
            return true;
        }
    }

}
